package me.zk.practice1.hw;

import java.util.*;

public class HWBJJ09 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int[] nums = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();

        int n = nums[0];
        int m = nums[1];
        List<String> list = new ArrayList<>();
        if (n < 1||n>100000||m<1||m>100000) {
            System.out.println("NULL");
            return;
        } else {
            for (int i = 0; i < m; i++) {
                String s =  scanner.nextLine();
                if (s.equals("1")){
                    break;
                }
                list.add(s);
            }

        }
        Map<Integer,Set<Integer>> map = new HashMap<>();
        for(String s : list){
            int[] array = Arrays.stream(s.split(" ")).mapToInt(Integer::parseInt).toArray();
            int a = array[0];
            int b = array[1];
            int c = array[2];
            if (a<1||a>n||b<1||b>n||(c!=0&&c!=1)) {
                System.out.println("da pian zi");
            } else if (c == 0) {
                Set<Integer> s1 = map.getOrDefault(a,new HashSet<Integer>());
               for (Integer key : s1) {
                   Set<Integer> s3 = map.getOrDefault(key,new HashSet<Integer>());
                   s3.add(b);
                   map.put(key,s3);
               }
                s1.add(b);
                map.put(a,s1);
                Set<Integer> s2 = map.getOrDefault(b,new HashSet<Integer>());
                for (Integer key : s1) {
                    Set<Integer> s4 = map.getOrDefault(key,new HashSet<Integer>());
                    s4.add(b);
                    map.put(key,s4);
                }
                s2.add(a);
                map.put(b,s2);
            } else{
                if (map.get(a).contains(b) ) {
                    System.out.println("we are a team");
                } else {
                    System.out.println("we are not a team");
                }
            }
        }


    }
}
